#include <algorithm>
#include <iostream>
#include <vector>
<<<<<<< HEAD
=======
#define LLD long long
>>>>>>> 05716ba729d670df7234547a0d5638459ce17d2b

using namespace std;

typedef long long int LLD;
const int MAXN = 1e3 + 10;
const int MAXA = 1e9 + 10;
<<<<<<< HEAD
int n;
LLD sum_a;
LLD sum[MAXN];
LLD a[MAXN];
LLD min_dis = 0x7fffffff;
vector<LLD> v(0);
=======
int n, sum_a;
LLD sum[MAXN];
LLD a[MAXN];
LLD min_dis = 0x7fffffff;
int l11, r11, l22, r22;
>>>>>>> 05716ba729d670df7234547a0d5638459ce17d2b

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }

<<<<<<< HEAD
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            v.push_back(sum[i] - sum[j - 1]);
        }
    }
    sort(v.begin(), v.end());
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            int s = sum[i] - sum[j - 1];
            auto it = find(v.begin(), v.end(), s);
            v.erase(it); x      

            for (auto &q : v) cout << q << " ";
            cout << endl;

            auto p = lower_bound(v.begin(), v.end(), s);
            if (p != v.end()) min_dis = min(min_dis, abs(s - *p));
            if (p != v.begin()) min_dis = min(min_dis, abs(s - *prev(p)));
=======
    int l1, r1;
    int l2, r2;
    LLD s1, s2;

    for (r1 = 1; r1 < n; r1++) {
        for (l2 = r1 + 1; l2 <= n; l2++) {
            l1 = r1, r2 = l2;

            while (l1 >= 1 && r2 <= n) {
                s1 = sum[r1] - sum[l1 - 1];
                s2 = sum[r2] - sum[l2 - 1];

                min_dis = min(min_dis, (LLD)abs(s1 - s2));

                if (s1 > s2)
                    r2++;
                else if (s1 < s2)
                    l1--;
                else
                    r2++, l1--;
            }

            while (l1 >= 1) {
                s1 = sum[r1] - sum[l1 - 1];
                min_dis = min(min_dis, (LLD)abs(s1 - s2));
                l1--;
            }

            while (r2 <= n) {
                s2 = sum[r2] - sum[l2 - 1];
                min_dis = min(min_dis, (LLD)abs(s1 - s2));
                r2++;
            }
>>>>>>> 05716ba729d670df7234547a0d5638459ce17d2b
        }
    }
    cout << min_dis;
}
